<?php

require_once 'ez_sql_core.php';
require_once 'ez_sql_mssql.php';

class Mssql_Db extends ezSQL_mssql
{

    /**
     * All the Mongo_Db instances
     *
     * @var array
     */
    protected static $instances = array();

    /**
     * Acts as a Multiton.
     * Will return the requested instance, or will create
     * a new one if it does not exist.
     *
     * @param string $name
     *            The instance name
     * @return Mssql_Db
     */
    public static function instance ($name = 'default')
    {
        if (\array_key_exists($name, static::$instances)) {
            return static::$instances[$name];
        }
        
        if (empty(static::$instances)) {
            \Config::load('db', true);
        }
        
        if (! ($config = \Config::get('db.mssql.' . $name))) {
            throw new \Exception('Invalid instance name given.');
        }
        
        static::$instances[$name] = new static($config);
        
        return static::$instances[$name];
    }

}
    